package net.inteidee.login;

import java.security.Principal;
import java.util.LinkedList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import net.inteidee.bean.entity.Operazione;
import net.inteidee.bean.entity.Ruolo;

import org.postgresql.Driver;


@ManagedBean(name="samplePrincipal")
@SessionScoped
public class SamplePrincipal implements Principal, java.io.Serializable {

    /**
     * @serial
     */
    private String name;
    
    private String  ruolo;
    
    private long idRuolo;
    
   private List<String> operazioni;
    
    
    

    public SamplePrincipal() {
		super();
	}

	/**
     * Create a SamplePrincipal with a Sample username.
     *
     * <p>
     *
     * @param name the Sample username for this user.
     *
     * @exception NullPointerException if the <code>name</code>
     *			is <code>null</code>.
     */
    public SamplePrincipal(String name,String ruolo) {
	if (name == null)
	    throw new NullPointerException("illegal null input");

	this.name = name;
	this.ruolo = ruolo;
	
    }

    /**
     * Return the Sample username for this <code>SamplePrincipal</code>.
     *
     * <p>
     *
     * @return the Sample username for this <code>SamplePrincipal</code>
     */
    public String getName() {
	return name;
    }

    
    public boolean canManageUsers(){
    	
    	
    	for(String operazione : operazioni)
    		if(operazione.equals("Gestione Utenti"))
    			return true;
    		
    	
    	return false;
    	
    	
    }
    
    
    
    
    
    
    /**
     * Return a string representation of this <code>SamplePrincipal</code>.
     *
     * <p>
     *
     * @return a string representation of this <code>SamplePrincipal</code>.
     */
    public String toString() {
	return("SamplePrincipal:  " + name);
    }

    /**
     * Compares the specified Object with this <code>SamplePrincipal</code>
     * for equality.  Returns true if the given object is also a
     * <code>SamplePrincipal</code> and the two SamplePrincipals
     * have the same username.
     *
     * <p>
     *
     * @param o Object to be compared for equality with this
     *		<code>SamplePrincipal</code>.
     *
     * @return true if the specified Object is equal equal to this
     *		<code>SamplePrincipal</code>.
     */
    public boolean equals(Object o) {
	if (o == null)
	    return false;

        if (this == o)
            return true;
 
        if (!(o instanceof SamplePrincipal))
            return false;
        SamplePrincipal that = (SamplePrincipal)o;

	if (this.getName().equals(that.getName()))
	    return true;
	return false;
    }
 
    
  

	public String getRuolo() {
		return ruolo;
	}

	public void setRuolo(String ruolo) {
		this.ruolo = ruolo;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getIdRuolo() {
		return idRuolo;
	}

	public void setIdRuolo(long idRuolo) {
		this.idRuolo = idRuolo;
	}

	public List<String> getOperazioni() {
		return operazioni;
	}

	public void setOperazioni(List<String> operazioni) {
		this.operazioni = operazioni;
	}

	
}
